package cfs.formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class PasswordFormBean extends FormBean {
	private String password;
	private String confirmedPassword;
	private String userName;

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConfirmedPassword() {
		return confirmedPassword;
	}

	public void setConfirmedPassword(String confirmedPassword) {
		this.confirmedPassword = confirmedPassword;
	}

	public void setUserName(String userName) {
		this.userName = userName.trim();
	}

	public String getUserName() {
		return userName;
	}

	@Override
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (confirmedPassword == null || confirmedPassword.length() == 0) {
			errors.add("Confirm Password is required");
		}

		if (password == null || password.length() == 0) {
			errors.add("Password is required");
		}

		if (errors.size() > 0)
			return errors;

		if (confirmedPassword.length() < 6 || password.length() < 6) {
			errors.add("Password must be more than 6 Letters");
		}

		if (errors.size() > 0)
			return errors;

		if (password.matches(".*[<>\"].*")) {
			errors.add("password  may not contain angle brackets or quotes");
		}

		if (confirmedPassword.matches(".*[<>\"].*")) {
			errors.add("password  may not contain angle brackets or quotes");
		}

		if (errors.size() > 0)
			return errors;

		if (!password.equals(confirmedPassword)) {
			errors.add("Password does not match");
		}

		return errors;
	}
}
